package while_lang.semantics.types;

import while_lang.semantics.Type;

public class IntegerType extends Type {
	public static final IntegerType TYPE = new IntegerType();

	@Override public boolean isType(Class<?> javaType) {
		return javaType == Integer.class;
	}

	@Override public boolean isCompatible(Class<?> javaType) {
		return javaType == Double.class || super.isCompatible(javaType);
	}

	@Override public boolean isCompatible(Type type) {
		return super.isCompatible(type) || type instanceof NumberType;
	}
	
	@Override public Object coerce(Object value) {
		if (value instanceof Double) {
			return ((Double)value).intValue();
		} else {
			return super.coerce(value);
		}
	}	

	@Override public String unparse() {
		return "int";
	}
	
}
